/**
 * 计算年龄
 */
export const getAge = function (strAge) {
  let birArr = strAge.split('-');
  let birYear = birArr[0];
  let birMonth = birArr[1];
  let birDay = birArr[2];

  d = new Date();
  let nowYear = d.getFullYear();
  let nowMonth = d.getMonth() + 1; //记得加1
  let nowDay = d.getDate();
  let returnAge;

  if (birArr == null) {
    return false
  }
  let d = new Date(birYear, birMonth - 1, birDay);
  if (d.getFullYear() === birYear && (d.getMonth() + 1) === birMonth && d.getDate() === birDay) {
    if (nowYear === birYear) {
      returnAge = 0; //
    } else {
      let ageDiff = nowYear - birYear; //
      if (ageDiff > 0) {
        if (nowMonth === birMonth) {
          let dayDiff = nowDay - birDay; //
          if (dayDiff < 0) {
            returnAge = ageDiff - 1;
          } else {
            returnAge = ageDiff;
          }
        } else {
          let monthDiff = nowMonth - birMonth; //
          if (monthDiff < 0) {
            returnAge = ageDiff - 1;
          } else {
            returnAge = ageDiff;
          }
        }
      } else {
        return  '出生日期晚于今天，数据有误'; //返回-1 表示出生日期输入错误 晚于今天
      }
    }
    return returnAge;
  } else {
    return ('输入的日期格式错误！');
  }
}
